import java.util.Scanner;

import javax.imageio.event.IIOReadProgressListener;

public class StudentManager {

	public static void main(String[] args) {
		// 输入一组学生的信息 Student[] array
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的数量：");
		int count = scanner.nextInt();
		// int[] array = new int[count];
		Student[] students = new Student[count];
		for (int i = 0; i < students.length; i++) {
			// for循环每遍历一次构造一个学生对象，放到数组里面
			System.out.println("请输入学生的编号：");
			int id = scanner.nextInt();
			System.out.println("请输入名字：");
			String name = scanner.next();
			System.out.println("请输入年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入班级：");
			String className = scanner.next();
			
			Student student = new Student();
			student.setId(id);
			student.setName(name);;
			student.setAge(age);
			student.setClassName(className);;
			
			// array[i] = 34;
			// 把每次构造的学生对象放到数组指定下标位置
			students[i]  = student;
		}
		
		// 打印Student[]数组里面所有学生的信息
		System.out.println("---------------");
		for (int i = 0; i < students.length; i++) {
			Student student = students[i];
			printStudent(student);
		}
		System.out.println("---------------");
		
		// while (true)
		// for (;;)
		
		while (true) {
			System.out.println("根据条件查询学生信息");
			System.out.println("根据id查找：1");
			System.out.println("根据name查找：2");
			System.out.println("根据age查找：3");
			System.out.println("根据className查找：4");
			System.out.println("输入0退出");
			System.out.println("----------------");
			int type = scanner.nextInt();
			if (type == 0) {
				break;
			}
			
			switch (type) {
			case 1: // 根据id查找
				System.out.println("请输入要查找的id：");
				int id = scanner.nextInt();// 用户输入的要查找的学生的id
				for (int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (student.getId() == id) {
						printStudent(student);
					}
				}
				break;
			case 2: // 根据名字来查找
				System.out.println("请输入要查找的name：");
				String name = scanner.next();// 用户输入的要查找的学生的name
				for (int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (name.equals(student.getName())) {
						printStudent(student);
					}
				}
				break;
			default:
				break;
			}
		}
	}
	
	
	public static void printStudent(Student student) {
		System.out.println(student.getId());
		System.out.println(student.getName());
		System.out.println(student.getAge());
		System.out.println(student.getClassName());
	}
}
